#include "StdAfx.h"
#include "AdminHelper.h"

namespace Librarian
{
	namespace Data
	{
		AdminEntity^ AdminHelper::ReadAdmin(DataRow^ row)
		{
			AdminEntity^ entity = gcnew AdminEntity();
			entity->AdminId = Convert::ToString(row["admin_id"]);
			entity->Password = Convert::ToString(row["password"]);
			entity->Name = Convert::ToString(row["name"]);
			entity->Contact = Convert::ToString(row["contact"]);
			return entity;
		}

		AdminEntity^ AdminHelper::ReadAdmin(DataTable^ table)
		{
			if(table->Rows->Count == 0)
			{
				return gcnew AdminEntity();
			}
			return ReadAdmin(table->Rows[0]);
		}
	
		array<AdminEntity^>^ AdminHelper::ReadAdmins(DataTable^ table)
		{
			List<AdminEntity^>^ entities = gcnew List<AdminEntity^>();
			for(int i = 0; i < table->Rows->Count; i++)
			{
				DataRow^ row = table->Rows[i];
				entities->Add(ReadAdmin(row));
			}
			return entities->ToArray();
		}

		
	}
}